function broadcast(componentName, eventName, params) {
  this.$refs && Object.keys(this.$refs).forEach(key => {
    /* 组件实例 */
    const child = this.$refs[key]
    /* 自定义标签名 */
    const name = child.$options?.name
    if (name === componentName || componentName === 'v-head') {
      /* 调用子组件的方法 */
      child[eventName] && child[eventName].apply(child, [params])
    }
  })
}
export default {
  methods: {
    dispatch(componentName, eventName, params) {
      var parent = this.$parent || this.$root
      var name = parent.$options?.name
      var level = 0
      while (parent && (!name || name !== componentName)) {
        parent = parent.$parent
        level++
        if (parent) {
          name = parent.$options?.name
        }
      }
      if (parent && parent[eventName]) {
        if (typeof params === 'object') params.level = level
        // debugger
        // params.parentData = parent.$options.propsData
        // parent.$emit.apply(parent, [eventName].concat(params))
        parent[eventName].apply(parent, [params])
      }
    },
    broadcast(componentName, eventName, params) {
      broadcast.call(this, componentName, eventName, params)
    },
    on(eventName, params) {
      // console.log('emitter-on--', eventName, params)
      const self = this
      if (!self[eventName]) {
        self[eventName] = params
      } else {
        self[eventName].apply(self, [params])
      }
    }
  }
}
